<%@page contentType="text/html;charset=UTF-8" language="java"%>
<%@page import="java.util.List"%>
<%@page import="javax.jdo.PersistenceManager"%>
<%@page import="javax.jdo.Query"%>
<%@page import="de.upb.messerschmidt.set.entity.Person"%>
<%@page import="de.upb.messerschmidt.set.jdo.PMF"%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Contact Registration</title>
</head>

<body>
	<h1>Contact Registration</h1>
	<p>Please choose which person shall have which contact</p>
	<form action="post/contact" method="post">
		<!-- Locations mit JSP abrufen -->
		<table>
			<tr>
				<td>User:</td>
				<td><select name="user" size="1">
						<%
							List<Person> results = null;
							PersistenceManager pm = PMF.get().getPersistenceManager();
							Query query = pm.newQuery(Person.class);
							query.setOrdering("name desc");
							try {
								results = (List<Person>) query.execute();
								if (!results.isEmpty()) {
									for (Person p : results) {
						%>
						<option>
							<%=p.getName() + ", " + p.getPrename()%>
						</option>
						<%
							}
								}
							}

							catch (Exception e) {
								e.printStackTrace();
							} finally {
								pm.close();
							}
						%>
				</select></td>
			</tr>
			<tr>
				<td>Contact:</td>
				<td><select name="contact" size="1">
						<%
							if (!results.isEmpty()) {
								for (Person l : results) {
						%>
						<option>
							<%=l.getName() + ", " + l.getPrename()%>
						</option>
						<%
							}
							}
						%>
				</select></td>
			</tr>
			<tr>
				<td><input type="submit" value="Submit" /></td>
				<td><input type="reset" value="Reset"></td>
			</tr>
		</table>
	</form>
</body>
</html>
